import vueAxios from "@/api/index";
import { useDynamicStore } from "@/stores/modules/dynamic";
// 文件解锁/上锁
export const IsLockConcat = async (type: string, status: boolean) => {
  const dynamicStore = useDynamicStore();
  const { visibleConfig, childVisibleConfig, tableSelect, childTableSelect, childTableData } = dynamicStore;
  const result = []; // 表示主表数组
  const result2 = []; // 表示子表数组
  switch (type) {
    case "parent":
      tableSelect.forEach((item: any) => {
        delete item.checkbox;
        result.push({ ...item, IsLock: status });
      });
      // 改变数据库数据
      if (result.length > 0) {
        const param = { list: result, tableName: visibleConfig.FMT.FMT_TableName };
        await vueAxios.put("Dynamic", param);
        // 修改本地表格数据
        tableSelect.forEach((item: any) => {
          item.IsLock = status;
        });
        childTableData.forEach(item => {
          item.IsLock = status;
        });
      }
      break;
    case "child":
      childTableSelect.forEach((item: any) => {
        delete item.checkbox;
        result.push({ ...item, IsLock: status });
      });
      // 改变数据库数据
      if (result.length > 0) {
        const param = { list: result, tableName: childVisibleConfig.FMT.FMT_TableName };
        await vueAxios.put("Dynamic", param);
        // 修改本地表格数据
        childTableSelect.forEach((item: any) => {
          item.IsLock = status;
        });
      }
      break;
  }
};
